<template>
<!-- 布局容器 -->
  <el-container class="container">
    <!-- 左侧栏 -->
    <el-aside width="200px">
      <div class="logo"></div>
      <!-- 导航菜单 -->
      <!-- default-active="1"  通过el-menu-item的 index 的值 来激活菜单项 -->
      <el-menu background-color="#023" style="border-right:none" text-color="#fff" :default-active="$router.path" router>
        <el-menu-item index="/">
        <i class="el-icon-s-home"></i>
        <span slot="title">数据概览</span>
      </el-menu-item>
      <el-menu-item index="/article">
        <i class="el-icon-document"></i>
        <span slot="title">内容管理</span>
      </el-menu-item>
      <el-menu-item index="/publish">
        <i class="el-icon-s-promotion"></i>
        <span slot="title">发布文章</span>
      </el-menu-item>
      </el-menu>
    </el-aside>
    <!-- 右侧栏 -->
    <el-container>
      <!-- 头部 -->
      <el-header>
        <span style="margin-right:20px">{{user.name||user.mobile}}</span>
        <el-link icon="el-icon-unlock" :underline="false" @click="logout()">退出</el-link>
      </el-header>
      <!-- 内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
  
</template>

<script>
import auth from '@/utils/auth'
export default {
 name:'Layout',
 data(){
   return{
     //用户信息对象
     user:{}
   }
 },
 async created () {
   //获取数据,设置数据
   const res = await this.$http.get('/v1_0/user/profile')
   this.user= res.data.data
 },
 methods: {
   logout(){
    //删除token
    //跳转登录
    auth.delToken()
    this.$router.push('/login')
   }
 }
}
</script>

<style scoped lang="less">
.container {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  .el-aside {
    
    background: #023;
      .logo {
      width: 200px;
      height: 60px;
      background:#023 url(../assets/logo.png) no-repeat center / 160px auto;
    }
  }
  .el-header {
    border-bottom: 1px solid #ddd;
    display: flex;
    line-height: 60px;
    justify-content: flex-end;
    align-items: center;
  }
}
</style>